import { defineConfig,loadEnv } from 'vite'
import {resolve} from 'path'
import vue from '@vitejs/plugin-vue'
import vitePluginVueSetupExtend from 'vite-plugin-vue-setup-extend'
// https://vitejs.dev/config/
export default ({mode}) => defineConfig({
  plugins: [vue(),vitePluginVueSetupExtend()],
  resolve: {                                      
    alias: {
      '@': resolve(__dirname, './src')         
    }                                          
  },
  publicDir:'public',
  build:{
    outDir:resolve(__dirname, '../express-ts/src/template'),
    assetsDir:'assets',
    emptyOutDir:true, // 因为打包后的目录不在项目根目录下 需要启动该配置项 每次打包将文件夹内容删除
    chunkSizeWarningLimit: 1500, // 将每个模块大小限制500KB 调整到 1500KB
    rollupOptions: { 
        output: {
            manualChunks(id) { // 将代码分割成多个块
                if (id.includes('node_modules')) {
                    return id.toString().split('node_modules/')[1].split('/')[0].toString();
                }
            },
        }
    }
  },
  server:{
    host:'0.0.0.0',
    port:8080,
    cors: true,
    proxy:{
        "^/api":{
            target:"http://localhost:4000"   
        }
    }
  },
  define:{
    "process.env":loadEnv(mode,process.cwd())
  }
})
